if(SERVER) then
	AddCSLuaFile("shared.lua")
	SWEP.AutoSwitchTo		= false
	SWEP.AutoSwitchFrom		= false
end

if(CLIENT) then
	SWEP.Slot = 5
	SWEP.SlotPos = 4
	SWEP.DrawAmmo = false
	SWEP.DrawCrosshair = false
	SWEP.IconLetter    		= "6"
	SWEP.IconFont			= "HL2MPSelectIcons"
	surface.CreateFont("HL2MP", ScreenScale(30), 500, true, true, "HL2MPSelectIcons")  
end

// Variables that are used on both client and server
SWEP.PrintName		= "Lock Pick"
SWEP.Instructions	= "Left click to pick a lock or gun vault"
SWEP.Contact		= ""
SWEP.Purpose		= ""

SWEP.ViewModelFOV	= 62
SWEP.ViewModelFlip	= false
SWEP.ViewModel 		= Model("models/weapons/v_crowbar.mdl")
SWEP.WorldModel 	= Model("models/weapons/w_crowbar.mdl")

SWEP.Spawnable			= true
SWEP.AdminSpawnable		= true

SWEP.Sound = Sound("physics/wood/wood_box_impact_hard3.wav")

SWEP.Primary.ClipSize		= -1					// Size of a clip
SWEP.Primary.DefaultClip	= 0				// Default number of bullets in a clip
SWEP.Primary.Automatic		= false				// Automatic/Semi Auto
SWEP.Primary.Ammo			= ""

SWEP.Secondary.ClipSize		= -1				// Size of a clip
SWEP.Secondary.DefaultClip	= -1				// Default number of bullets in a clip
SWEP.Secondary.Automatic	= false				// Automatic/Semi Auto
SWEP.Secondary.Ammo			= ""

SWEP.Other					= true


/*---------------------------------------------------------
   Name: SWEP:Initialize()
   Desc: Called when the weapon is first loaded
---------------------------------------------------------*/
function SWEP:Initialize()
	self:SetWeaponHoldType("melee")
util.PrecacheSound("physics/flesh/flesh_impact_bullet" .. math.random(3, 5) .. ".wav")
util.PrecacheSound("weapons/iceaxe/iceaxe_swing1.wav")
end


/*---------------------------------------------------------
   Name: SWEP:Precache()
   Desc: Use this function to precache stuff
---------------------------------------------------------*/
function SWEP:Precache()
end


/*---------------------------------------------------------
   Name: SWEP:PrimaryAttack()
   Desc: +attack1 has been pressed
---------------------------------------------------------*/

function SWEP:PrimaryAttack()
	self.Weapon:SetNextPrimaryFire(CurTime() + .4)

	local trace = self.Owner:GetEyeTrace()
	local bullet = {}
		bullet.Num    = 1
		bullet.Src    = self.Owner:GetShootPos()
		bullet.Dir    = self.Owner:GetAimVector()
		bullet.Spread = Vector(0, 0, 0)
		bullet.Tracer = 0
		bullet.Force  = 1
		bullet.Damage = 0
	if (ValidEntity(trace.Entity)) then	
		if (trace.HitPos:Distance(self.Owner:GetShootPos()) <= 75 && ValidEntity(trace.Entity) && trace.Entity:IsDoor()) then
			self.Weapon:SendWeaponAnim(ACT_VM_HITCENTER)
			self.Owner:FireBullets(bullet) 
			self.Weapon:EmitSound("physics/flesh/flesh_impact_bullet" .. math.random(3, 5) .. ".wav")
			
			if(trace.Entity.UnlockAmmount == nil) then
				trace.Entity.UnlockAmmount = 0
			elseif(trace.Entity.UnlockAmmount < 4) then
				if self.Owner:GetNWBool("Tool Kitd") then
					trace.Entity.UnlockAmmount = UnlockAmmount +2
				else
					trace.Entity.UnlockAmmount = UnlockAmmount +1
				end
			else
				trace.Entity.UnlockAmmount = 0
				if SERVER then
					if trace.Entity:GetTable().locked == true then
					trace.Entity:Fire("unlock", "", .5)
					trace.Entity:Fire("open", "", .6)
					trace.Entity.locked = false
					Notify(self.Owner, 4, 3, "Door unlocked!")
					else
					trace.Entity:Fire("lock", "", .6)
					trace.Entity:Fire("close", "", .5)
					trace.Entity.locked = true
					Notify(self.Owner, 4, 3, "Door locked!")
					end
				end
			end
		elseif (trace.HitPos:Distance(self.Owner:GetShootPos()) <= 75 && ValidEntity(trace.Entity) && (trace.Entity:GetClass()=="structure_gunvault" || trace.Entity:GetClass()=="structure_pillbox")) then
			self.Weapon:SendWeaponAnim(ACT_VM_HITCENTER)
			self.Owner:FireBullets(bullet) 
			self.Weapon:EmitSound("physics/flesh/flesh_impact_bullet" .. math.random(3, 5) .. ".wav")
			
			if(trace.Entity.UnlockAmmount == nil) then
				trace.Entity.UnlockAmmount = 0
			elseif(trace.Entity.UnlockAmmount < 9) then
				if self.Owner:GetNWBool("Tool Kitd") then
					trace.Entity.UnlockAmmount = trace.Entity.UnlockAmmount +2
				else
					trace.Entity.UnlockAmmount = trace.Entity.UnlockAmmount +1
				end
			else
				trace.Entity.UnlockAmmount = 0
				if SERVER then
					Notify(self.Owner, 4, 3, trace.Entity.PrintName .. "unlocked!")
					trace.Entity:SetUnLocked()
				end
			end
		elseif (trace.HitPos:Distance(self.Owner:GetShootPos()) <= 75 && ValidEntity(trace.Entity) && trace.Entity:GetClass()=="structure_moneyvault") then
			self.Weapon:SendWeaponAnim(ACT_VM_HITCENTER)
			self.Owner:FireBullets(bullet) 
			self.Weapon:EmitSound("physics/flesh/flesh_impact_bullet" .. math.random(3, 5) .. ".wav")
			
			if(trace.Entity.UnlockAmmount == nil) then
				trace.Entity.UnlockAmmount = 0
			elseif(trace.Entity.UnlockAmmount < 30) then
				if self.Owner:GetNWBool("Tool Kitd") then
					trace.Entity.UnlockAmmount = trace.Entity.UnlockAmmount + 2
				else
					trace.Entity.UnlockAmmount = trace.Entity.UnlockAmmount + 1
				end
			else
				trace.Entity.UnlockAmmount = 0
				if SERVER then
					Notify(self.Owner, 4, 3, "money vault unlocked")
					trace.Entity:SetUnLocked()
				end
			end
		else
			self.Weapon:SendWeaponAnim(ACT_VM_HITCENTER)
			self.Owner:FireBullets(bullet) 
			self.Weapon:EmitSound("physics/flesh/flesh_impact_bullet" .. math.random(3, 5) .. ".wav")
		end
	end

end

function SWEP:SecondaryAttack()

end

function SWEP:DrawWeaponSelection(x, y, wide, tall, alpha)
	draw.SimpleText(self.IconLetter, self.IconFont, x + wide/2, y + tall*0.2, Color(255, 210, 0, 255), TEXT_ALIGN_CENTER)
end